From: Mark A. Hershberger Date: Fri, 8 Jan 2010 08:22:19 +0000 (+0000) Subject: follow up r60763 X-Git-Tag: 1.31.0-rc.0~38354 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=934c2bcd50a47e1f20ef33eafb222387dd44f5ff;p=lhc%2Fweb%2Fwiklou.git follow up r60763 Recover the -{T| }- rule. Add the ability to test for it to the parserTests and add a test for it. Add a couple of disabled tests that I think demonstrate bugs in the LanguageTranslator --- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index dad1ccadcb..f1ef4fb906 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -261,6 +261,12 @@ class Parser if ( !$t || $t instanceof FakeTitle ) { $t = Title::newFromText( 'NO TITLE' ); } + // If we still don't have a Title object, make sure we can + // convert whatever we've been passed to a string. + if ( !$t instanceOf Title && is_string( "$t" ) ) { + $t = Title::newFromText( "$t" ); + } + if ( strval( $t->getFragment() ) !== '' ) { # Strip the fragment to avoid various odd effects $this->mTitle = clone $t; @@ -329,14 +335,6 @@ class Parser # No more strip! wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); $text = $this->internalParse( $text ); - // internalParse took care of the notitleconvert bit, so title conversion is here. - if ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable()) { - $converted = $wgContLang->convert( $title ); - if ( !$converted instanceOf Title ) { - $converted = Title::newFromText( $converted ); - } - $this->setTitle( $converted ); - } $text = $this->mStripState->unstripGeneral( $text ); @@ -355,13 +353,23 @@ class Parser $this->replaceLinkHolders( $text ); - # the position of the convert() call should not be changed. it - # assumes that the links are all replaced and the only thing left - # is the mark. + // The position of the convert() call should not be changed. it + // assumes that the links are all replaced and the only thing left + // is the mark. if ( $this->mDoContentConvert && !$this->mTitle->isConversionTable()) { $text = $wgContLang->convert( $text ); } + // A title may have been set in a conversion rule. + // Note that if a user tries to set a title in a conversion + // rule but content conversion was not done, then the parser + // won't pick it up. This is probably expected behavior. + if ( $wgContLang->getConvRuleTitle() ) { + $this->setTitle( $wgContLang->getConvRuleTitle() ); + } elseif ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable() ) { + $this->setTitle( $wgContLang->convert( $title ) ); + } + $text = $this->mStripState->unstripNoWiki( $text ); wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) ); diff --git a/languages/Language.php b/languages/Language.php index 6aa9c9b2af..72b694f804 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -34,11 +34,12 @@ if( function_exists( 'mb_strtoupper' ) ) { */ class FakeConverter { var $mLang; + var $mConvRuleTitle; function FakeConverter($langobj) {$this->mLang = $langobj;} function autoConvertToAllVariants($text) {return $text;} function convert($t, $i) {return $t;} function getVariants() { return array( $this->mLang->getCode() ); } - function getPreferredVariant() {return $this->mLang->getCode(); } + function getPreferredVariant() { return $this->mLang->getCode(); } function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {} function getExtraHashOptions() {return '';} function getParsedTitle() {return '';} @@ -2664,4 +2665,11 @@ class Language { $text = $this->getMessageFromDB( $msg ); return str_replace( '$1', $this->formatNum( $size ), $text ); } + + /** + * Get the conversion rule title, if any. + */ + function getConvRuleTitle() { + return $this->mConverter->mConvRuleTitle; + } } diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 7bd487dae5..113c470b25 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -31,6 +31,7 @@ class LanguageConverter { var $mDescCodeSep = ':', $mDescVarSep = ';'; var $mUcfirst = false; var $mHeaderVariant; + var $mConvRuleTitle = false; const CACHE_VERSION_KEY = 'VERSION 6'; @@ -459,8 +460,8 @@ class LanguageConverter { */ function applyManualConv( $convRule ) { // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom - // conversion in title - $title = $convRule->getTitle(); + // conversion in title + $this->mConvRuleTitle = $convRule->getTitle(); // apply manual conversion table to global table $convTable = $convRule->getConvTable(); @@ -544,7 +545,7 @@ class LanguageConverter { * @return string converted text * @public */ - function convert( $text, $isTitle ) { + function convert( $text ) { global $wgDisableLangConversion; if ( $wgDisableLangConversion ) return $text; @@ -558,10 +559,6 @@ class LanguageConverter { // Remove the last delimiter (wasn't real) $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) ); - if ( $isTitle ) { - error_log("title2: $converted\n"); - $this->mConvertedTitle = $converted; - } return $converted; } @@ -1110,13 +1107,13 @@ class ConverterRule { * Parse rules conversion. * @private */ - function getRuleConvertedStr( $variant, $doConvert ) { + function getRuleConvertedStr( $variant ) { $bidtable = $this->mBidtable; $unidtable = $this->mUnidtable; if ( count( $bidtable ) + count( $unidtable ) == 0 ) { return $this->mRules; - } elseif ( $doConvert ) { // the text converted + } else { // display current variant in bidirectional array $disp = $this->getTextInBidtable( $variant ); // or display current variant in fallbacks @@ -1142,8 +1139,6 @@ class ConverterRule { } } return $disp; - } else { // no convert - return $this->mRules; } } @@ -1271,15 +1266,13 @@ class ConverterRule { // proces H,- flag or T only: output nothing $this->mRuleDisplay = ''; } elseif ( in_array( 'S', $flags ) ) { - // true hard-coded now since we shouldn't be called if we're not converting - $this->mRuleDisplay = $this->getRuleConvertedStr( $variant, true ); + $this->mRuleDisplay = $this->getRuleConvertedStr( $variant ); } else { $this->mRuleDisplay = $this->mManualCodeError; } // process T flag if ( in_array( 'T', $flags ) ) { - // true hard-coded now since we shouldn't be called if we're not converting - $this->mRuleTitle = $this->getRuleConvertedStr( $variant, true ); + $this->mRuleTitle = $this->getRuleConvertedStr( $variant ); } if ( in_array( '-', $flags ) ) { diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index b59e3f5a2f..bf4f00fea6 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -493,6 +493,10 @@ class ParserTest { $result = $this->tidy($result); } + if ( isset( $opts['showtitle'] ) ) { + $out = $parser->mTitle . "\n$out"; + } + $this->teardownGlobals(); if( $result === $out && ( $noxml === true || $this->wellFormed( $out ) ) ) { diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 68835ba6d7..5dd0ef6804 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -6929,15 +6929,15 @@ Taiwan is Taiwan. !! test Adding explicit conversion rule for title (T flag) !! options -language=zh variant=zh-tw +language=zh variant=zh-tw showtitle !! input Should be stripped-{T|zh:China;zh-tw:Taiwan}-! !! result +Taiwan

Should be stripped!

!! end - !! test Raw output of variant escape tags (R flag) !! options @@ -6949,7 +6949,6 @@ Raw: -{R|zh:China;zh-tw:Taiwan}-

!! end - !! test Do not convert roman numbers to language variants !! options @@ -7515,6 +7514,47 @@ title=[[Main Page]] #section !! end +!! test +Adding explicit conversion rule for title (T flag) +!! options +language=zh variant=zh-tw showtitle **** disabled (for now) because I think it uncovers a bug and I want a reminder +!! input +Should be stripped-{T|zh:China;zh-tw:Taiwan}-! +!! result +Taiwan +

Should be stripped! +

+!! end + +!! test +Adding explicit conversion rule for title (T flag) +!! options +language=zh variant=zh showtitle **** disabled (for now) because I think it uncovers a bug and I want a reminder +!! input +Should be stripped-{T|zh:China;zh-tw:Taiwan}-! +!! result +China +

Should be stripped! +

+!! end + +!! test +Explicit session-wise language variant mapping (A flag and - flag) +!! options +language=zh variant=zh **** disabled (for now) because I think it uncovers a bug and I want a reminder +!! input +Taiwan is not China. +But -{zh:China;zh-tw:Taiwan}- is China, +(This-{-|zh:China;zh-tw:Taiwan}- should be stripped!) +and -{China}- is China. +!! result +

Taiwan is not China. +But Taiwan is Taiwan, +(This should be stripped!) +and China is China. +

+!! end + TODO: more images more tables